#ifndef TICKCOUNTRUNNER_HPP
#define TICKCOUNTRUNNER_HPP

#include <QObject>
#include <QtCore/QList>
#include <QtCore/QThread>

#include "tickcountrunnable.hpp"
#include "tickcountrunnablefactory.hpp"

/**
 * @brief Manager for the TickCountRunnables
 * @details This class is used to manage all created TickCountRunnables.
 * They will be created, stored and managed automatically once started.
 *
 * @see TickCountRunnable
 *
 * @class TickCountRunner tickcountrunner.hpp "tickcountrunner.hpp"
*/
class TickCountRunner : public QObject
{
    Q_OBJECT

public:
    /**
     * @brief Default Constructor
     *
     * @fn TickCountRunner
    */
    explicit TickCountRunner();

    /**
     * @brief Default Destructor
     * @details Will stop the Thread before destructing it
     *
     * @fn ~TickCountRunner
    */
    ~TickCountRunner();

    /**
     * @brief Start a specified amount of Runners
     * @details If the count is set to 0 (zero), the idealThreadCount will be used.
     * This will determine the number of CPU cores and run this amount of Threads in parallel.
     * If there are more than the specified amount of Runners currently running, nothing will be done.
     *
     * @fn startRunners
     * @param count
    */
    void startRunners(int count = 0);

    /**
     * @brief Stop a specified amount of Runners
     * @details If the count is 0 (zero), all workers are stopped.
     * If the amount is greater than currently running worker count, all workers are stopped.
     *
     * @fn stopRunners
     * @param count
     * @return int
    */
    int stopRunners(int count = 0);

private slots:
    /**
     * @brief Will remove the currently finished Runner out of the managed list
     *
     * @fn onRunnerFinished
    */
    void onRunnerFinished();

private:
    QList<TickCountRunnable*> m_threadList;
    static int m_runnerId;
};

#endif // TICKCOUNTRUNNER_HPP
